package com.fone.player.sns.view;

import com.fone.player.sns.util.SNSUtil;
import com.fone.player.util.L;

import android.view.Window;
import android.webkit.WebView;
import cn.sharesdk.tencent.qzone.QZoneWebShareAdapter;

public class MyQZoneWebShareAdapter extends QZoneWebShareAdapter {
	public static final String  TAG = "MyQZoneWebShareAdapter";
	
	private static boolean isShowing = false;
	
	public static boolean open = false;

	
	@Override
	public void onCreate() {
		// 设置页面以Dialog的方式展示
//		getActivity().setTheme(android.R.style.Theme_Dialog);
		getActivity().requestWindowFeature(Window.FEATURE_NO_TITLE);

		super.onCreate();
		if(!open){
			getActivity().finish();
			return ;
		}
		if(isShowing){
			getActivity().finish();
			return ;
		}
		
		isShowing = true;
		SNSUtil.setSNSPageState(isShowing);

		// 修改页面标题
//		getTitleLayout().getTvTitle().setText(R.string.qzone_customer_share_style);

		// 下面的代码可以拦截webview加载的页面地址，但是添加后，分享操作将可能无法正确执行
//		getWebBody().setWebViewClient(new WebViewClient() {
//			public boolean shouldOverrideUrlLoading(WebView view, String url) {
//				System.out.println("=========== " + url);
//				return super.shouldOverrideUrlLoading(view, url);
//			}
//		});

	}
	
	@Override
	public void onPause() {
		super.onPause();
		WebView webBody = getWebBody();
		if(webBody!=null){
			try {
				L.v(TAG, "onPause", "mWebView.onPause()");
				webBody.getClass().getMethod("onPause").invoke(webBody,(Object[])null);
			} catch (Exception e) {
				L.e(TAG, "onPause", e.getMessage());
			}
		}
	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		if(isShowing){
			isShowing = false;
			open = false;
			SNSUtil.setSNSPageState(isShowing);
		}
	}
	
}
